package com.zhentao.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhentao.dto.system.AssginRoleDto;
import com.zhentao.dto.system.SysUserDto;
import com.zhentao.entity.system.SysUser;
import com.zhentao.service.SysUserService;
import com.zhentao.vo.common.Result;
import com.zhentao.vo.common.ResultCodeEnum;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/admin/system/sysUser")
public class SysUserController {

    @Resource
    private SysUserService sysUserService ;
    /**
     * 用户动态查询+分页
     * @param sysUserDto
     * @return
     */
    @PostMapping(value = "/findByPage")
    public Result<Page<SysUser>> findByPage(@RequestBody SysUserDto sysUserDto) {
        Page<SysUser> pageInfo = sysUserService.findByPage(sysUserDto);
        return Result.build(pageInfo , ResultCodeEnum.SUCCESS);
    }

    /**
     * 新增用户
     * @param sysUser
     * @return
     */
    @PostMapping("/saveSysUser")
    public Result saveSysUser(@RequestBody SysUser sysUser) {
        sysUserService.saveSysUser(sysUser);
        return Result.build(null , ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改用户
     * @param sysUser
     * @return
     */
    @PutMapping("/updateSysUser")
    public Result updateSysUser(@RequestBody SysUser sysUser) {
        sysUserService.updateSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 删除用户
     * @param userId
     * @return
     */
    @DeleteMapping(value = "/deleteById/{userId}")
    public Result deleteById(@PathVariable(value = "userId") Long userId) {
        sysUserService.deleteById(userId) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    /**
     * 保存角色数据
     * @param assginRoleDto
     * @return
     */
    @PostMapping("/doAssign")
    public Result doAssign(@RequestBody AssginRoleDto assginRoleDto) {
        sysUserService.doAssign(assginRoleDto) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

}